<?php
$g4_path = '../';
$lib =  "$g4_path/lib.php";
$menu = 7;
require_once ("$g4_path/common.php");
require_once ($lib);
require_once ('../lib/Template_.class.php');
$tpl = new Template_;
require_once ('./mydesk.lib.php');
require_once('../head.ebvill.php');

$monthSelected = isset($_GET['month']) ? $_GET['month'] : date('m');
$nextYear = $prevYear = $yearSelected = isset($_GET['year']) ? $_GET['year'] : date('Y');
$nextMonth = $monthSelected+1;
$prevMonth = $monthSelected-1; 
if($nextMonth > 12) {
    $nextMonth = 1; 
    $nextYear = $yearSelected+1; 
}
if($prevMonth < 1) {
    $prevMonth = 12; 
    $prevYear = $yearSelected-1; 
}
?>
<style type="text/css" >
    .w_sun,.w_sat {
            background-color:#ffffcc;
    }
</style>
<script>
function openTimeTable(year, month, day, dow, studentno) {
    window.open('pop_timetable_detail.php?year='+year+'&month='+month+'&day='+day+'&dow='+dow+'&student='+studentno,'timetable','scrollbars=yes,width=500,height=400');
    return false;
}

</script>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody><tr>
<td><img width="747" height="45" src="../images/sub_contents_title_timetable.gif"/></td>
</tr>
<tr>
<td><img width="747" height="17" src="../images/sub_contents_title_tail.gif"/></td>
</tr>
<tr>
<td><img width="747" height="94" src="../images/sub_contents_desk_preview.jpg"/></td>
</tr>
<tr>
<td>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody><tr>
<td width="19" valign="top"><img width="19" height="573" src="../images/sub_contents_tail_left.gif"/></td>
<td valign="top"><table width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody><tr>
<td width="13" height="30"><img width="1" height="1" src="../images/blank.gif"/></td>
<td height="30"><img width="1" height="1" src="../images/blank.gif"/></td>
</tr>
<tr>
<td><img width="1" height="1" src="../images/blank.gif"/></td>
<td><table cellspacing="0" cellpadding="0" border="0" class="font">
<tbody><tr>
<td valign="top" height="40"><table cellspacing="0" cellpadding="0" border="0">
<tbody><tr>
<td><img width="217" height="9" src="../images/sub_today_form_top.gif"/></td>
</tr>
<tr>
<td background="../images/sub_today_form_bg.gif"><table width="100%" cellspacing="0" cellpadding="0" border="0" class="font">
<tbody><tr>
<td><img width="217" height="20" src="../images/sub_today_form_title.gif"/></td>
</tr>
<tr>
<td height="24" background="../images/sub_today_form_date.gif"><div align="center"><?php echo date('Y년 m월 d일'); ?></div></td>
</tr>
<tr>
<td><table cellspacing="0" cellpadding="0" border="0" align="center">
<tbody><tr>
<td><table width="180" cellspacing="0" cellpadding="0" border="0" align="center">
<tbody>
<?php
$year = date('y');
$month = date('m');
$date = 'w_'.strtolower(date('D'));

/* for test 
$year = 2008;
$month= 1;
$date = 'w_mon'; 
$userid = 'admin'; 
*/

$_res = sql_query($sql);
$size = sizeof($_todayCourseData); 
for($i=0;$i<$size;$i++) {
    $_iconset = date('i') == $_todayCourseData['starttime'] ? 'on' : 'off';
?>
<tr>
<td width="80" height="20"><a target="_self" href="#"><?=$_todayCourseData[$i]['name']?></a></td>
<td width="50"><?=$_todayCourseData[$i]['ampm']?> <?=$_todayCourseData[$i]['time']?>시</td>
<td width="24"><img width="24" height="15" src="../images/sub_today_icon_<?php echo $_iconset; ?>.gif"/></td>
</tr>
<?
}
if($size == 0) {
    echo '<tr><td width="200" align="center" height="30">오늘은 수업이 없습니다.</td></tr>';

}
?>
</tbody></table></td>
</tr>
</tbody></table></td>
</tr>
</tbody></table></td>
</tr>
<tr>
<td><img width="217" height="9" src="../images/sub_today_form_bottom.gif"/></td>
</tr>
</tbody></table></td>
<td width="7" valign="top"><img width="1" height="1" src="../images/blank.gif"/></td>
<td valign="top"><table cellspacing="0" cellpadding="0" border="0">
<tbody><tr>
<td><img width="453" height="9" src="../images/sub_month_form_top.gif"/></td>
</tr>
<tr>
<td background="../images/sub_month_form_bg.gif"><table width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody><tr>
<td height="20" background="../images/sub_month_form_title.gif"><div align="right" class="style1"><?php echo $yearSelected; ?>년 <?php echo $monthSelected; ?>월<img width="15" height="1" src="../images/blank.gif"/></div></td>
</tr>
<tr>
<td><img width="453" height="24" src="../images/sub_month_form_date.gif"/></td></tr>
<!----- TIMETABLE ---->
<tr>
<td>
<table class="timetable" cellspacing="0" cellpadding="0" border="0" align="center">
<?php
    
    $now = mktime(0,0,0, $monthSelected, 1, $yearSelected);
    $limit = date('t', $now);
    $today = date('d', $now);
    $startDow = date('w', $now);

    $lastWeek = false;
    $days = 1-$startDow;
    $dows = array('w_sun','w_mon','w_tue','w_wed','w_thu','w_fri','w_sat');
    
    $sql = "SELECT sum(c.w_sun), sum(c.w_mon), sum(c.w_tue), sum(c.w_wed), sum(c.w_thu), sum(c.w_fri), sum(c.w_sat), co.student from course c, course_order co, g4_member g where c.year = $yearSelected AND c.month = $monthSelected AND co.student = g.mb_no AND g.mb_id = '$userid' AND co.course = c.no AND co.status='2' GROUP BY co.student";
    
    $weekDays  = mysql_fetch_row(mysql_query($sql));
    $studentno = $weekDays[7]; 

    while(!$lastWeek) :
    ?>
    <tr>
<?php
    for($i = 0; $i < 7; $i++, $days++) :
        if($dows[$i]!="w_sun" && $dows[$i]!="w_sat")  //일 토 제거
        {        
        ?>
<?php
        //if($weekDays[$i] > 0 && $days > 0 && $days <= $limit) {
        if($days > 0 && $days <= $limit) {

            if($weekDays[$i] > 0) { ///// 수업이 있는날
?>
<td width="86" valign="top" height="43" background="../images/sub_month_form_day_bg_on.gif"><table width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody><tr>
<td height="20"><div align="right"><?=$days?><img width="1" height="1" src="../images/blank.gif"/><img width="5" height="1" src="../images/blank.gif"/></div></td>
</tr>
<tr>
<td><div align="center">
<a onclick="return openTimeTable(<?php echo $yearSelected?>, <?php echo $monthSelected?>, <?php echo $days?>, '<?php echo $dows[$i]?>', <?php echo $studentno?>)" href="#"><?php echo $weekDays[$i]?>개 수업</a></div></td></tr>
</tbody></table></td>
<!--
            <td valign="top" width="86" valign="top" background="../images/sub_month_form_day_bg_off.gif" height="40" class="<?php echo $dows[$i]?>"><?php if($days >= 1 && $days <= $limit)echo  $days?>
<br />
<img width="5" height="15" align="absmiddle" alt="" src="../admin/images/point_page_title.gif" />
<a onclick="return openTimeTable(<?php echo $yearSelected?>, <?php echo $monthSelected?>, <?php echo $days?>, '<?php echo $dows[$i]?>', <?php echo $studentno?>)" href="#"><?php echo $weekDays[$i]?>개 수업</a> 
</td>
-->
        <?php
            } else { // 수업이 없는날
?>
<td width="86" valign="top" height="43" background="../images/sub_month_form_day_bg_off.gif"><table width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody><tr>
<td height="20"><div align="right"><?=$days?><img width="1" height="1" src="../images/blank.gif"/><img width="5" height="1" src="../images/blank.gif"/></div></td>
</tr>
<tr>
<td><div align="center"></div></td>
</tr>
</tbody></table></td>
<?
            }
        } else {
            echo '<td></td>';

        }
    }
            if($days >= $limit) {
                $lastWeek = true; 
            }
            endfor;
        ?>
    </tr>
    <?php
    endwhile;
?>
<!--- END OF TIMETABLE -->
</table>
<tr>
<td height="25"><table width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody><tr>
<td width="30"><div align="right"><a href="./timetable.php?year=<?php echo $prevYear; ?>&month=<?php echo $prevMonth; ?>"><img width="17" height="17" align="absmiddle" src="../images/sub_desk_buttom_pre.gif"/></div></td>
<td><div align="center">수업을 클릭하시면 해달 날짜 시간표를 보실 수 있습니다.</div></td>
<td width="30"><a href="./timetable.php?year=<?php echo $nextYear; ?>&month=<?php echo $nextMonth; ?>"><img width="17" height="17" align="absmiddle" src="../images/sub_desk_buttom_next.gif"/></div></td>
</tr>
</tbody></table></td>
</tr>
</tbody></table></td>
</tr>
<tr>
<td><img width="453" height="9" src="../images/sub_month_form_bottom.gif"/></td>
</tr>
</tbody></table></td>
</tr>
</tbody></table></td>
</tr>
<tr>
<td width="13"><img width="1" height="1" src="../images/blank.gif"/></td>
<td height="20"><img width="1" height="1" src="../images/blank.gif"/></td>
</tr>
</tbody></table></td>
</tr>
</tbody></table></td>
</tr>
<tr>
<td><img width="747" height="144" border="0" usemap="#Map" src="../images/sub_contents_copy.gif"/>
<map id="Map" name="Map"><area target="_blank" href="http://www.turnway.com/new/introduction/introduce.php" coords="35,76,76,92" shape="rect"/><area target="_blank" href="http://www.turnway.com/new/privacy/ad.php" coords="87,76,145,92" shape="rect"/><area target="_blank" href="http://www.turnway.com/new/privacy/privacy.php" coords="159,77,241,92" shape="rect"/><area target="_blank" href="http://www.turnway.com/new/notice/list.php?tbl_name=notice6" coords="254,77,295,92" shape="rect"/><area target="_blank" href="http://www.turnway.com/new/introduction/location.php" coords="304,76,362,91" shape="rect"/><area target="_blank" href="http://www.turnway.com/" coords="26,33,150,60" shape="rect"/>
</map></td>
</tr>
<tr>
<td height="20"><img width="1" height="1" src="../images/blank.gif"/></td>
</tr>
</tbody></table>


<?php
require_once('../tail.ebvill.php');
